package com.tong.hao.ac.service.controller.test;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName ConfigController
 * @Author 友野浩二
 * @Date 2019/11/10 14:43
 * @Description 分布式配置客户端测试类
 * @Version 1.0
 *
 * <pre>
 *     默认情况下,Config Client分布式配置中心的客户端是不会自动感知配置的变化的。此时,可以使用/refresh端点来进行配置更新。
 * </pre>
 */
@RestController
@RefreshScope
public class ConfigController {

    @Value("${ac.name:哈哈哈}")
    String acName;

    @Autowired
    Environment environment;

    @RequestMapping(value = "/acName", method = RequestMethod.GET)
    public String acName() {
        return this.acName;
    }

    @RequestMapping(value = "/acName2", method = RequestMethod.GET)
    public String acName2() {
        return this.environment.getProperty("ac.name", "我是你粑粑!");
    }

}
